use rocket::response::Responder;
use serde::Serialize;

#[derive(Debug, Serialize, Clone)]
pub enum ServerError {
    ServiceError(String),
    ServiceErrorStr(&'static str),
    TaskError(String),
    TaskErrorStr(&'static str),
    WorkflowError(String),
    WorkflowErrorStr(&'static str),
    DataError(String),
    DataErrorStr(&'static str),
    BuiltinTaskError(String),
    BuiltinTaskErrorStr(&'static str),
    SystemError(String),
    SystemErrorStr(&'static str),
    LogFileError(String),
    LogFileErrorStr(&'static str),
    ServiceCannotReach,
}

impl<'r, 'o: 'r> Responder<'r, 'o> for ServerError {
    fn respond_to(self, request: &'r rocket::Request<'_>) -> rocket::response::Result<'o> {
        rocket::response::status::BadRequest(Some(format!("{:?}", self))).respond_to(request)
    }
}